package com.micookie.v2ex.utils;

import android.widget.Toast;

import com.micookie.v2ex.App;

/**
 * Toast工具类
 */
public class ToastUtils {

    private static Toast toast;

    /**
     * Toast发送消息，默认Toast.LENGTH_SHORT
     *
     * @param msg
     */
    public static void show(final String msg) {
        show(msg, Toast.LENGTH_SHORT);
    }

    /**
     * Toast发送消息，默认Toast.LENGTH_LONG
     *
     * @param msg
     */
    public static void showLong(final String msg) {
        show(msg, Toast.LENGTH_LONG);
    }

    /**
     * Toast发送消息
     *
     * @param msg
     * @param len
     */
    public static void show(final String msg, final int len) {
        cancelCurrentToast();
        toast = Toast.makeText(App.getInstance(), msg, len);
        toast.show();

    }

    /**
     * 关闭当前Toast
     */
    public static void cancelCurrentToast() {
        if (toast != null) {
            toast.cancel();
        }
    }
}